package com.zmn.plat.services.impl.service.item.servicetime;

import com.zmn.common.utils.date.DateUtil;

import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTime;
import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTimeQuery;
import com.zmn.plat.persistence.interfaces.service.item.servicetime.ServServiceTimeDao;
import com.zmn.plat.services.interfaces.service.item.servicetime.ServServiceTimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 项目服务时长接口实现类
 *
 * @author yangshuangping
 * @since  2021/07/27 10:36
 */
@Slf4j
@Service
public class ServServiceTimeServiceImpl implements ServServiceTimeService {

    private static final String TAG = "项目服务时长基础服务接口";

    @Resource
    private ServServiceTimeDao servServiceTimeDao;

    @Override
    public ServServiceTime findById(Integer serviceTimeId) {

        if (Objects.isNull(serviceTimeId)) {
            log.error("[{}],根据id查询数据serviceTimeId为null", TAG);
            return null;
        }
        return servServiceTimeDao.findById(serviceTimeId);
    }

    @Override
    public List<ServServiceTime> listPageByQuery(ServServiceTimeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(servServiceTimeDao.countByQuery(query));
        return servServiceTimeDao.listPageByQuery(query);
    }

    @Override
    public List<ServServiceTime> listByQuery(ServServiceTimeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return servServiceTimeDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(ServServiceTimeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return servServiceTimeDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ServServiceTime servServiceTime) {

        if (Objects.isNull(servServiceTime.getServiceTimeId())){
            log.error("[{}],根据id修改数据,servServiceTime为null", TAG);
            return null;
        }
        return servServiceTimeDao.updateByKey(servServiceTime);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        servServiceTimeDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert (ServServiceTime servServiceTime){

        if (Objects.isNull(servServiceTime)){
            log.error("[{}],新增数据,servServiceTime为null", TAG);
            return null;
        }
        return servServiceTimeDao.insert(servServiceTime);
    }

    @Override
    public Integer deleteByKey(Integer serviceTimeId) {

        if (Objects.isNull(serviceTimeId)){
            log.error("[{}],根据id删除数据,serviceTimeId为null", TAG);
            return null;
        }
        return servServiceTimeDao.deleteByKey(serviceTimeId);
    }

}